package com.easidea.tim.flex.remote
{
	import com.easidea.tim.flex.util.AppAlert;
	
	import mx.messaging.Channel;
	import mx.messaging.ChannelSet;
	import mx.messaging.channels.AMFChannel;
	import mx.messaging.messages.ErrorMessage;
	import mx.rpc.events.FaultEvent;
	import flash.external.ExternalInterface;
	
	public class BaseDao
	{
		private var productChannel:Channel;
		public function BaseDao()
		{
			//TODO: implement function
		}
		protected function buildChannelSet():ChannelSet {
			if (productChannel == null)
				{
				var url:String = ExternalInterface.call("getCurrentUrl");
				if(url!=null && url.toLowerCase().indexOf("file://")==-1)
            		url =  url.toLowerCase();				
            	else
            		url = "http://localhost:8080";						
					productChannel=new AMFChannel("my-amf", url+"/tim-hls/messagebroker/amf");
					var cs:ChannelSet=new ChannelSet();
					cs.addChannel(productChannel);
				}
			return cs;	
		}
		protected function _Fault  (event:FaultEvent, token:Object = null) : void {	
			var errorMsg:ErrorMessage  = event.message as  ErrorMessage;		
			AppAlert.show(errorMsg.faultString);
		} 
	}
}